<template>
	<view>
	<view class="my-page-content ">
		<view class="my-title">添加床铺信息 </view>
		<view v-for="(item, index) in bedList" :key="index">
			<view class="my-m-title">{{item.title}}</view>
			<view v-for="(subItem, subIndex) in item.list" :key="subIndex" class="mb20 flex-between">
				 <span>{{subItem.sizeName}}</span>
				<van-stepper :min="0" :max="20" @change="onChange($event, subItem)" :value="subItem.num"/>
			</view>
	   </view>
	
	</view>
</view>
</template>

<script>
	export default {
		props: {
			  bedSelectList:  Array 
		},
		data() {
			return {
				bedList: [
					 {	
						title: '双人床',
						list: [
							   {
								   title: '双人床',
								   type: 'double',
								   id: 1,
								   size: [1.8, 2.2],
								   num: 0,
								   sizeName: '宽1.8m-2.2m'
							   },
							  {
									title: '双人床',
									type: 'double',
									id: 2,
									size: [1.5, 1.79],
									num: 0,
									sizeName: '宽1.5m-1.79m'
							  },
							  ]
					},
					{	
						title: '单人床',
						list: [
							{
							   title: '单人床',
							   type: 'single',
							   size: [1.25, 1.49],
							   id: 3,
							   num: 0,
							   sizeName: '宽1.25m-1.49m'
						   },
						   {
								title: '单人床',
								type: 'single',
								size: [1, 1.24],
								id: 4,
								num: 0,
								sizeName: '宽1m-1.24m'
						   },
						],
					},
			     	{	
					
						title: '上下床',
						list:[
							  {
							   title: '上下床',
							   type: 'bunk',
							   size: [1.25, 1.49],
							   num: 0,
							   id: 5,
							   sizeName: '宽1.2m-1.49m'
							 },
						  {
						    title: '上下床',
						    type: 'bunk',
						    size: [1, 1.24],
						    num: 0,
							id: 6,
						    sizeName: '宽1m-1.19m'
						  },
						  ]
					},
				   {	
						title: '婴儿床',
						list: [{
							   title: '婴儿床',
							   type: 'crib',
							   size: [],
							   num: 0,
							   id: 7,
							   sizeName: '婴儿床'
						 }]
					}
				]
			}
		},
		onShow() {
			// console.log('show',  this.bedList)
		},
		mounted() {
			this.handleData();
		},
 		methods: {
			 handleData() {
			    if(this.bedSelectList.length == 0) {
					return;
				}
				 this.bedList.forEach((item, index, arr) =>{
					 for( let i=0; i<arr[index].list.length; i++) {
						 let subItem = arr[index].list[i];
						 for(let j=0; j< this.bedSelectList.length; j++) {
							 if(subItem.id == this.bedSelectList[j].id) {
								 subItem.num =  this.bedSelectList[j].num;
								 break;
							 }
 						 }
 					 } 
					 
				 });
				 console.log('jinru this.bedSelectList',  this.bedList)
			 },
			  onChange(event, item) {
				 item.num = event.detail
			  },
			 nextStep() {
				 const list = [];
				 this.bedList.forEach(item =>{
					 item.list.forEach(subItem =>{
						 if(subItem.num > 0 ) {
							 list.push(subItem);
						 }
					 })
				 });
				 if(list.length == 0) {
					 this.$toast('请填写床铺信息');
					 return false;
				 }
				 return list;
			  
			 }
		}
	}
	
</script>

<style>
</style>